//
//  ZDBNewsListViewController.m
//  ZDB
//
//  Created by Kk on 2020/4/9.
//  Copyright © 2020 ZDB. All rights reserved.
//

#import "ZDBNewsListViewController.h"
#import "ZDBBanner.h"
#import "ZDBNewTableViewCell.h"
#import "ZDBNewsInfoViewController.h"
@interface ZDBNewsListViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic,strong) NoNetworkView * workView;
@end

@implementation ZDBNewsListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self placeholderViewWithFrame:_tableView.frame NoNetwork:NO];
}
- (NSMutableArray *)dataSource
{
    if (!_dataSource) {
        _dataSource = [NSMutableArray new];
    }
    return _dataSource;
}
#pragma  mark -----懒加载
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, UIScreenWidth, UIScreenHeight  - kStatusBarAndNavigationBarHeight)style:UITableViewStyleGrouped];
        _tableView.tableFooterView = [UIView new];
        _tableView.separatorColor = CELLCOLOR;
        _tableView.delegate = self;
        _tableView.dataSource=self;
        _tableView.backgroundColor =  VIEWBGCOLOR;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 0.001)];
        [_tableView registerNib:[UINib nibWithNibName:@"ZDBNewTableViewCell" bundle:nil]  forCellReuseIdentifier:@"ZDBNewTableViewCell"];
    
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 118;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZDBNewTableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"ZDBNewTableViewCell" forIndexPath:indexPath];
    cell.model = _dataSource[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ZDBNotice * notice = self.dataSource[indexPath.row];
    ZDBNewsInfoViewController * newsVC = [[ZDBNewsInfoViewController alloc] init];
    newsVC.title = @"公告详情";
    newsVC.model = notice;
    [self.navigationController pushViewController:newsVC animated:YES];
}

- (void)placeholderViewWithFrame:(CGRect)frame NoNetwork:(BOOL)NoNetwork
{
    if (self.dataSource.count == 0)
    {
        [_workView removeFromSuperview];
        _workView = [[NoNetworkView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height) NoNetwork:NoNetwork];
        [self.tableView addSubview:_workView];
        //_workView.centerY = self.collectionView.centerY-100;
    }else
    {
        [_workView dissmiss];
    }
    
}
@end
